import defaultSetting from "../common/utils/defaultSetting";
import BasicLayout from "../layouts/BasicLayout/index.vue";
import BlankLayout from "../layouts/BlankLayout/index.vue";
import store from "../store";
import components from "./components";
import TenantBasicLayout from "../layouts/TenantBasicLayout/index.vue";
import Diaosettings from "@/views/Approval/Appset/Diaosettings.vue";

/**
 * @description: 访问路径添加子应用前缀
 * @param {String}path
 * @return {*}
 */

const getRedirectPath = (to) => {
  let name = store.getters.selectedMenuNames[to.name]; // 选中菜单name
  if (!name) {
    // 进入第一个子菜单
    const parentRoute = to.matched[0];
    name = parentRoute.children[0].name;
  }
  return { name };
};

/**
 * @description: 路由表
 */
const routes = [
  // 无菜单页面
  {
    name: "Approval",
    path: "/approval",
    component: BlankLayout,
    redirect: (to) => getRedirectPath(to),
    children: [
      {
        path: "index",
        name: "Home",
        component: components.Home,
        meta: { title: "审批", keepAlive: false },
      },
      {
        name: "dataCenter",
        path:"dataCenter",
        component: components.DataCenter,
        meta: { title: "审批中心", keepAlive: false },
      },
      {
        path: "set",
        name: "SetApproval",
        component: components.SetApproval,
        meta: { title: "审批设置", keepAlive: false },
      },
      {
        path: "start",
        name: "StartApproval",
        component: components.StartApproval,
        meta: { title: "发起审批", keepAlive: false },
      },
      {
        path: "detail",
        name: "ApprovalDetail",
        component: components.ApprovalDetail,
        meta: { title: "审批详情", keepAlive: false },
      },
      {
        path: "Diaosettings",
        name: "Diaosettings",
        component: components.Diaosettings,
      },
      {
        path: "ApprovalSettings",
        name: "ApprovalSettings",
        component: components.ApprovalSettings,
      },

      // 有菜单页面
      {
        path: "manage",
        name: "Manage",
        component: BlankLayout,
        redirect: (to) => getRedirectPath(to),
        children: [
          {
            path: "index",
            name: "ApprovalManage",
            component: components.ApprovalManage,
            meta: { title: "审批管理", keepAlive: false },
          },
          {
            path: "data",
            name: "DataManage",
            component: components.DataManage,
            meta: { title: "数据管理", keepAlive: false },
          },
        ],
      },
      {
        path: "print",
        name: "ApprovalPrint",
        component: components.ApprovalPrint,
        meta: { title: "审批打印", keepAlive: false },
      },
    ],
  },
  {
    name: "TenantApproval",
    path:  "/tenantApproval",
    component: BlankLayout,
    redirect: (to) => getRedirectPath(to),
    children: [
      {
        path: "index",
        name: "TenantHome",
        component: components.TenantHome,
        meta: { title: "审批", keepAlive: false },
      },
      {
        path: "set",
        name: "TenantSetApproval",
        component: components.TenantSetApproval,
        meta: { title: "审批设置", keepAlive: false },
      },
      {
        path: "start",
        name: "TenantStartApproval",
        component: components.TenantStartApproval,
        meta: { title: "发起审批", keepAlive: false },
      },
      {
        path: "detail",
        name: "TenantApprovalDetail",
        component: components.TenantApprovalDetail,
        meta: { title: "审批详情", keepAlive: false },
      },
      // 有菜单页面
      {
        path: "manage",
        name: "TenantManage",
        component: TenantBasicLayout,
        redirect: (to) => getRedirectPath(to),
        children: [
          {
            path: "index",
            name: "TenantApprovalManage",
            component: components.TenantApprovalManage,
            meta: { title: "审批管理", keepAlive: false },
          },
          {
            path: "data",
            name: "TenantDataManage",
            component: components.TenantDataManage,
            meta: { title: "数据管理", keepAlive: false },
          },
        ],
      },
      {
        path: "print",
        name: "TenantApprovalPrint",
        component: components.TenantApprovalPrint,
        meta: { title: "审批打印", keepAlive: false },
      },
    ],
  },
  {
    name: "orgCommon",
    path: "/orgCommon",
    component: components.OrgCommon,
  },
  {
    name: "microApp",
    path: "/microApp",
    component: BlankLayout,
    children: [
      {
        path: "otherDetail",
        name: "DetailShow",
        component: components.DetailShow,
        meta: {title: "", keepAlive: false},
      },
    ],
  },

];

export default routes;
